import http from '@/utils/http'
import city from './city'

export default {
  namespaced: true,
  state: {
    showDateList: [],
    cinemaTimeStamp: [] // 各影院播放电影的时间戳
  },
  mutations: {
    changeShowDateList (state, arr) {
      // console.log(arr, 'arr-arr-arr')
      state.showDateList = arr
    },
    changeCinemaTimeStamp (state, arr) {
      // console.log(arr, '影院电影时间戳arr-arr-arr')
      state.cinemaTimeStamp = arr
    }
  },
  actions: { // 支持异步和同步
    // 获取城市的时间戳
    getTimeStampCity (store, filmId) {
      console.log(store.state, '1~1~1~1~1~1~1~1')
      return http({
        url: `/gateway/?filmId=${filmId}&cityId=${store.state.city.cityId}&k=2522567`,
        headers: {
          'X-Host': 'mall.film-ticket.cinema.film-show-cinema'
        }
      }).then(response => {
        // console.log(response.data.data.showCinemas, '电影时间戳')
        const showDateList = response.data.data.showCinemas ? response.data.data.showCinemas.map(item => item.showDate) : []
        store.commit('changeShowDateList', showDateList)

        return response.data.data.showCinemas
      })
    },
    // 获取影院时间戳
    getTimeStampCinema (store, cinemaId) {
      return http({
        url: `/gateway/?cinemaId=${cinemaId}&k=7550847`,
        headers: {
          'X-Host': 'mall.film-ticket.film.cinema-show-film'
        }
      }).then(response => {
        // console.log(response.data.data.films, '影院电影时间戳')

        store.commit('changeCinemaTimeStamp', response.data.data.films)
        return response.data.data.films
      })
    }
  },
  modules: {
    city
  }
}
